<template>
  <div class="switch-container">
    <input class="toggle-checkbox" id="toggle-switch" type="checkbox" v-model="checked" />
    <label class="switch" for="toggle-switch">
      <div class="toggle">
        <div class="led"></div>
      </div>
    </label>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
const checked = ref(false);
</script>

<style scoped>
.switch-container {
  position: relative;
  width: 150px;
  height: 60px;
  background: #d6d6d6;
  border-radius: 50px;
  box-shadow:
    inset -8px -8px 16px #ffffff,
    inset 8px 8px 16px #b0b0b0;
  transition: background 0.3s;
}
.toggle-checkbox {
  display: none;
}
.switch {
  position: absolute;
  top: 50%;
  left: 0;
  width: 100%;
  height: 100%;
  transform: translateY(-50%);
  border-radius: 50px;
  overflow: hidden;
  cursor: pointer;
}
.toggle {
  position: absolute;
  width: 80px;
  height: 50px;
  background: linear-gradient(145deg, #d9d9d9, #bfbfbf);
  border-radius: 50px;
  top: 5px;
  left: 5px;
  box-shadow:
    -4px -4px 8px #ffffff,
    4px 4px 8px #b0b0b0;
  transition: all 0.3s ease-in-out;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding-left: 10px;
}
.led {
  width: 10px;
  height: 10px;
  background: grey;
  border-radius: 50%;
  box-shadow: 0 0 10px 2px rgba(0, 0, 0, 0.2);
  transition: all 0.3s ease-in-out;
}
.toggle-checkbox:checked + .switch .toggle {
  left: 65px;
  background: linear-gradient(145deg, #cfcfcf, #a9a9a9);
  box-shadow:
    -4px -4px 8px #ffffff,
    4px 4px 8px #8a8a8a;
}
.toggle-checkbox:checked + .switch .led {
  background: yellow;
  box-shadow: 0 0 15px 4px yellow;
}
.switch:hover .toggle {
  box-shadow:
    -4px -4px 12px #ffffff,
    4px 4px 12px #9b9b9b;
}
/* 暗色主题适配 */
:deep(.dark) .switch-container {
  background: #23232a;
  box-shadow:
    inset -8px -8px 16px #2a2a2a,
    inset 8px 8px 16px #18181c;
}
:deep(.dark) .toggle {
  background: linear-gradient(145deg, #23232a, #18181c);
  box-shadow:
    -4px -4px 8px #2a2a2a,
    4px 4px 8px #18181c;
}
:deep(.dark) .toggle-checkbox:checked + .switch .toggle {
  background: linear-gradient(145deg, #23232a, #18181c);
  box-shadow:
    -4px -4px 8px #2a2a2a,
    4px 4px 8px #18181c;
}
:deep(.dark) .led {
  background: #888;
}
:deep(.dark) .toggle-checkbox:checked + .switch .led {
  background: #ffe066;
  box-shadow: 0 0 15px 4px #ffe066;
}
</style> 